package org.casper.demo1;

import java.io.File;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;


/**
 * 使用dom4j进行解析 books.xml文档
 * project_name:XMLTest<br>
 * package_name:org.casper.demo1<br>
 * file_name:Dom4jParse.java<br>
 * @author Casper<br>
 * create_date:2015年10月8日 下午3:13:33<br>
 * modified_date:
 * description:
 *
 */
public class Dom4jParse {
	public static void main(String[] args) {
		try {
			//1.加载jar包
			//2.获得Sax解析器
			SAXReader reader = new SAXReader();
			Document booksDocument = reader.read(new File("E:/mxp_codes/XMLTest/src/org/casper/demo1/books.xml"));
			//3.开始解析 
 			Element booksEle = booksDocument.getRootElement(); 	//获取根节点
			List<Element> bookEleList = booksEle.elements();	//获取某个节点的所有的子节点
			for (Element element : bookEleList) {
				List<Element> bookAttriEleList = element.elements();
				for (Element element2 : bookAttriEleList) {
					System.out.println(element2.getText());
				}
			}
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		
	}
}
